package com.jiaai.cloud.api;

import com.jiaai.cloud.base.exception.ServiceException;
import com.jiaai.cloud.base.redis.util.RedisUtil;
import com.jiaai.cloud.base.util.IdGenerate;
import com.jiaai.cloud.base.util.IdWorkUtil;
import com.jiaai.cloud.base.util.RestResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author 佳爱网络科技
 * @version V1.0
 * @title CommonAPI
 * @since 2017/8/2
 */
@RestController
@RequestMapping("/api/v1/common")
public class CommonAPI {
    @Autowired
    private IdWorkUtil idWorkUtil;

    @Autowired
    private RedisUtil redisUtil;
    /**
     * 获取一个游客Id
     * @return
     */
    @GetMapping("/getVisitorsId")
    private Object generateVisitorsId(){
        try {
            return idWorkUtil.generateId("visitoresId",4) ;
        } catch (ServiceException e) {
            return IdGenerate.generateUserId();
        }
    }

    @GetMapping("/sendMobileCode")
    public   Object sendPhoneCode(String mobile){
        String code="321445";
        redisUtil.hashSet(0,"code",mobile,code);
        return  RestResultGenerator.genSuccessResult("发送成功");
    }
}
